#include "./../inc/draw.h"
int color = YELLOW;
int radius = 5;

int main()
{
    Init();
    toolbar_init();
    int count = 0;
    // 读取触摸屏数据
    struct input_event buf;
    int x = -1, y = -1;

    while (1)
    {

        memset(&buf, 0, sizeof(buf));
        fread(&buf, sizeof(buf), 1, fp_touch);

        if (buf.type == EV_ABS)
        {
            if (buf.code == ABS_X)
            {
                x = buf.value * 800 / 1024;
            }
            else if (buf.code == ABS_Y)
            {
                y = buf.value * 480 / 600;
            }
        }

        if (buf.type == EV_SYN && x != -1 && y != -1)
        {
            if (y <= 48)
            {
                if (x > 5 && x < 45)
                {
                    color = WHITE;
                }
                if (x > 55 && x < 95)
                {
                    if (color == BLACK)
                    {
                        color = WHITE;
                    }
                    radius = 5;
                }
                else if (x > 105 && x < 145)
                {
                    if (color == BLACK)
                    {
                        color = WHITE;
                    }
                    radius = 10;
                }
                else if (x > 155 && x < 195)
                {
                    if (color == BLACK)
                    {
                        color = WHITE;
                    }
                    radius = 15;
                }
                else if (x > 205 && x < 245)
                {
                    if (color == BLACK)
                    {
                        color = WHITE;
                    }
                    radius = 20;
                }
                else if (x > 255 && x < 305)
                {
                    color = YELLOW;
                }
                else if (x > 305 && x < 355)
                {
                    color = RED;
                }
                else if (x > 355 && x < 405)
                {
                    color = GREEN;
                }
                else if (x > 405 && x < 455)
                {
                    color = BLUE;
                }
                else if (x > 455 && x < 505)
                {
                    color = BLACK;
                }
                else if (x > 505 && x < 555)
                {
                    radius = 5;
                    color = BLACK;
                }
                else if (x > 555 && x < 605)
                {
                    radius = 10;
                    color = BLACK;
                }
                else if (x > 605 && x < 655)
                {
                    radius = 15;
                    color = BLACK;
                }
                else if (x > 655 && x < 705)
                {
                    radius = 20;
                    color = BLACK;
                }
                else if (x > 750 && x < 800)
                {
                    memset(lcd_mmap, 0, 800 * 480 * 4);
                    toolbar_init();
                }
            }
            else
            {
                touch(x, y, radius, color);
            }
        }
    }
}
